package com.cn.transfer.common.utils;

import com.cn.transfer.handle.MessageStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class MessageStrategyFactory {

    private final Map<String, MessageStrategy> strategyMap = new HashMap<>();

    @Autowired
    public MessageStrategyFactory(List<MessageStrategy> strategies) {
        log.info(strategies.toString());
        for (MessageStrategy strategy : strategies) {
            strategyMap.put(strategy.getMsgType(), strategy);
        }
    }

    public MessageStrategy createStrategy(String msgType) {
        return strategyMap.get(msgType);
    }
}
